//
//  ButtonCell.swift
//  Employee
//
//  Created by swordjoy on 2017/4/11.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import UIKit

class ButtonCell: UITableViewCell {

  static var identifier = "ButtonCell.swordjoy"
  
  static var height: CGFloat = 60
  
  var title: String = "" {
    
    didSet { button.setTitle(title, for: .normal) }
    
  }
  var buttonClick: VoidClosure?
  
  fileprivate var contentV: UIView!
  fileprivate var button: UIButton!
  
  // MARK: - life cycle
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    backgroundColor = UIColor.clear
    
    create()
    
  }
  
  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

}

// MARK: - action

extension ButtonCell {
  
  @objc fileprivate func buttonAction() {
    
    guard let closure = buttonClick else { return }
    closure()
    
  }
  
}

// MARK: - fileprivate

extension ButtonCell {
  
  fileprivate func create() {
    
    contentV = UIView()
    contentView.addSubview(contentV)
    contentV.backgroundColor = UIColor.clear
    contentV.snp.makeConstraints { (make) in
      make.left.top.equalTo(0)
      make.bottom.right.equalTo(0)
    }
    
    button = UIButton()
    contentV.addSubview(button)
    button.titleLabel?.font = GlobalConfig.system16Font
    button.setTitleColor(UIColor.white, for: .normal)
    button.backgroundColor = GlobalConfig.BGSkyBlueColor
    button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
    button.snp.makeConstraints { (make) in
      make.left.top.equalTo(5)
      make.bottom.right.equalTo(-5)
    }
    button.layer.cornerRadius = 4
    button.layer.masksToBounds = true
    
    
  }
  
}
